package com.sky.service.impl;

import com.google.gson.Gson;
import com.sky.dto.futu.ModifyOrderRequestDto;
import com.sky.dto.futu.PlaceOrderRequestDto;
import com.sky.entity.futu.*;
import com.sky.utils.HttpUtil;
import com.sky.utils.UrlBuilder;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class FutuDealService {

    private final Gson gson = new Gson();
    @Value("${futu.base-url}")
    private String BASE_URL;
    private final String prefix = "/deal";

    // 拼接 BASE_URL 和 prefix
    private String getBaseUrlWithPrefix() {
        return BASE_URL + prefix;
    }
    @Autowired
    private HttpUtil httpUtil;

    // code='', start='', end=''
    public List<Deal> getHistoryDeals(String code, String start, String end) throws IOException {
        String url = new UrlBuilder(getBaseUrlWithPrefix()  + "/deals")
                .addParam("code", code)
                .addParam("start", start)
                .addParam("end", end).build();
        return httpUtil.getList(url, Deal.class);
    }

    public List<Deal> getTodayDeals(String code) throws IOException {
        String url = new UrlBuilder(getBaseUrlWithPrefix()  + "/deals_today")
                .addParam("code", code).build();
        return httpUtil.getList(url, Deal.class);
    }
}
